#include "stm32f4xx.h"                 
#include "delay.h"
#include "led.h"
#include "usart.h"
#include "ff.h"
#include "mymalloc.h"
#include "lvgl_app.h"
#include "WM8960.h"
#include "Play_Music.h"




 int main(void)
 {
    FRESULT res;
    FATFS *fs;


    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

    LED_Init();
    usart1_init(115200);
    delay_init(HCLK_Div8);
    SD_NVIC_Configuration();
       
    
    fs = mymalloc(sizeof(FATFS));
    // 每次上电后挂载SD卡
    res = f_mount(fs,"0:",1);
    if(res != FR_OK)
    {
        printf("f_mount error\r\n");
    }
    myfree(fs);
    
    res = WM8960_Init();
    if(res == 0)  {
        printf("WM8960_Init complete !!\r\n");
    }
    else  {
        printf("WM8960_Init fail ! Error code: %d\r\n", res);
        while(1)  {
            delay_ms(1000);
        }
    }

    ScanWavefiles("0:/Music");
    

//    while(1)
//    {

        PlayWaveFile();
//        Music_Num++;
//        if(Music_Num >= Music_Num_MAX)
//            Music_Num = 0;
//    }

 	/* 不再使用文件系统，取消挂载文件系统 */
 	f_mount(NULL,"0:",1);

    lvgl_app_init();
    lv_test();

    while(1){
    
        delay_ms(5);
        lv_timer_handler();
    } 
 }




